import json

from bs4 import BeautifulSoup
from loguru import logger

from com.arcfox.manager.redis_task_manager import RedisTaskManager
from com.arcfox.middleware import async_mysql_middleware as db
from com.arcfox.school.processor.base_processor import BaseProcessor


class MajorProcessor(BaseProcessor):
    def __init__(self):
        super().__init__()

    async def store_major_detail(self, data, data_version):
        mapping = db.MysqlMapping("tb_major_info")
        data["data_version"] = data_version
        major_code = data["major_code"]
        exist = await mapping.query({"major_code": major_code},["id"])
        if exist:
            logger.info("{} 已经存在，更新数据", major_code)
            await mapping.update(data, {"major_code": major_code})
            return
        await mapping.insert(data)
